from flask import render_template
from blueprints import personal_blueprint
from models import PackInstance, QueryOneInstance, Personal, Role
from tools.decorate import pack_session


@personal_blueprint.route('/my/page/personal', methods=['GET' ])
@pack_session
def get_my_page_of_personal(data):
    data.update(PackInstance(QueryOneInstance(Personal,{"uid":data['session']['uid']})))
    data.update(PackInstance(QueryOneInstance(Role,{"uid":data['session']['uid']})))
    data['writeable'] = True
    return render_template('pages/personal/persoanl.html',data=data)

@personal_blueprint.route('/anyone/page/personal/<int:uid>', methods=['GET'])
@pack_session
def get_anyone_page_of_personal(data):
    data.update(PackInstance(QueryOneInstance(Personal,{"uid":data['route']['uid']})))
    data.update(PackInstance(QueryOneInstance(Role,{"uid":data['session']['uid']})))
    data['writeable']= (data['session']['uid'] == data['route']['uid'])

    return render_template('pages/personal/persoanl.html',data=data)